<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>i2c: C:/Users/Jon/Downloads/OOP/db-control/dbUser.php Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">i2c
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">C:/Users/Jon/Downloads/OOP/db-control/dbUser.php</div>  </div>
</div>
<div class="contents">
<a href="db_user_8php.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;?php
<a name="l00002"></a>00002 
<a name="l00018"></a>00018 <span class="comment">/*</span>
<a name="l00019"></a>00019 <span class="comment"> * This is the database file.</span>
<a name="l00020"></a>00020 <span class="comment"> * It contacts the control file to know</span>
<a name="l00021"></a>00021 <span class="comment"> * which user data to get and set.</span>
<a name="l00022"></a>00022 <span class="comment"> * It is the only file that has the SQL queries and MySQL connections</span>
<a name="l00023"></a>00023 <span class="comment"> *</span>
<a name="l00024"></a>00024 <span class="comment"> */</span>
<a name="l00025"></a>00025 
<a name="l00026"></a><a class="code" href="classdb_user.html">00026</a> <span class="keyword">class </span><a class="code" href="classdb_user.html">dbUser</a> {
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="classdb_user.html#aea6c4d653e217f31256ded5783ed58f4">00029</a>     <span class="keyword">static</span> <span class="keyword">function</span> <a class="code" href="classdb_user.html#aea6c4d653e217f31256ded5783ed58f4">createTable</a>() {
<a name="l00030"></a>00030         <span class="comment">//Create table User</span>
<a name="l00031"></a>00031         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;</span>
<a name="l00032"></a>00032 <span class="stringliteral">            create table sysuser(</span>
<a name="l00033"></a>00033 <span class="stringliteral">                userID                  int             NOT NULL AUTO_INCREMENT,</span>
<a name="l00034"></a>00034 <span class="stringliteral">                username                varchar(25)     NOT NULL,</span>
<a name="l00035"></a>00035 <span class="stringliteral">                password                varchar(32)     NOT NULL,</span>
<a name="l00036"></a>00036 <span class="stringliteral">                fname                   varchar(25)     NOT NULL,</span>
<a name="l00037"></a>00037 <span class="stringliteral">                lname                   varchar(25)     NOT NULL,</span>
<a name="l00038"></a>00038 <span class="stringliteral">                permissionLevel         text            NOT NULL,</span>
<a name="l00039"></a>00039 <span class="stringliteral">                constraint PK_sysuser PRIMARY KEY (userID)</span>
<a name="l00040"></a>00040 <span class="stringliteral">                );</span>
<a name="l00041"></a>00041 <span class="stringliteral">    &quot;</span>;
<a name="l00042"></a>00042         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00043"></a>00043         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00044"></a>00044         mysql_close();
<a name="l00045"></a>00045         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00046"></a>00046             echo mysql_error();
<a name="l00047"></a>00047             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00048"></a>00048         }
<a name="l00049"></a>00049 
<a name="l00050"></a>00050         <span class="comment">//Previous query was successful.</span>
<a name="l00051"></a>00051         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00052"></a>00052     }
<a name="l00053"></a>00053 
<a name="l00058"></a><a class="code" href="classdb_user.html#a48a9c3492291c38e6113e40e04deb2ed">00058</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#a48a9c3492291c38e6113e40e04deb2ed">getAllUsers</a>() {
<a name="l00059"></a>00059         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;SELECT * FROM sysuser&quot;</span>;
<a name="l00060"></a>00060         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00061"></a>00061         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00062"></a>00062         mysql_close();
<a name="l00063"></a>00063         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00064"></a>00064             echo mysql_error();
<a name="l00065"></a>00065             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067         <span class="comment">//Query was successful</span>
<a name="l00068"></a>00068         <span class="keywordflow">return</span> <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>;
<a name="l00069"></a>00069     }
<a name="l00070"></a>00070 
<a name="l00076"></a><a class="code" href="classdb_user.html#ab989f4032e1c02f23d31b176a8b94b3b">00076</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#ab989f4032e1c02f23d31b176a8b94b3b">updateUser</a>($u) {
<a name="l00077"></a>00077         <span class="keywordflow">if</span> (!($u instanceof <a class="code" href="class_user.html">User</a>)) {
<a name="l00078"></a>00078             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00079"></a>00079         }
<a name="l00080"></a>00080         $userID = $u-&gt;getUserID();
<a name="l00081"></a>00081         <a class="code" href="db-control_2inc_2db_info_8php.html#a0eb82aa5f81cf845de4b36cd653c42cf">$username</a> = $u-&gt;getUsername();
<a name="l00082"></a>00082         <a class="code" href="db-control_2inc_2db_info_8php.html#a607686ef9f99ea7c42f4f3dd3dbb2b0d">$password</a> = $u-&gt;getPassword();
<a name="l00083"></a>00083         $fname = $u-&gt;getFName();
<a name="l00084"></a>00084         $lname = $u-&gt;getLName();
<a name="l00085"></a>00085         $permissionlevel = $u-&gt;getPermissionLevel();
<a name="l00086"></a>00086 
<a name="l00087"></a>00087         <span class="keywordflow">if</span> (<a class="code" href="db-control_2inc_2db_info_8php.html#a0eb82aa5f81cf845de4b36cd653c42cf">$username</a> != <span class="stringliteral">&#39;&#39;</span>) {
<a name="l00088"></a>00088             $success *= mysql_query(<span class="stringliteral">&quot;UPDATE sysuser SET username=&#39;$username&#39; </span>
<a name="l00089"></a>00089 <span class="stringliteral">                    WHERE userID=$userID&quot;</span>);
<a name="l00090"></a>00090         }
<a name="l00091"></a>00091         <span class="keywordflow">if</span> (<a class="code" href="db-control_2inc_2db_info_8php.html#a607686ef9f99ea7c42f4f3dd3dbb2b0d">$password</a> != <span class="stringliteral">&#39;&#39;</span>) {
<a name="l00092"></a>00092             $success *= mysql_query(<span class="stringliteral">&quot;UPDATE sysuser SET password=&#39;$password&#39; </span>
<a name="l00093"></a>00093 <span class="stringliteral">                    WHERE userID=$userID&quot;</span>);
<a name="l00094"></a>00094         }
<a name="l00095"></a>00095         <span class="keywordflow">if</span> ($fname != <span class="stringliteral">&#39;&#39;</span>) {
<a name="l00096"></a>00096             $success *= mysql_query(<span class="stringliteral">&quot;UPDATE sysuser SET fname=&#39;$fname&#39; WHERE</span>
<a name="l00097"></a>00097 <span class="stringliteral">                    userID=$userID&quot;</span>);
<a name="l00098"></a>00098         }
<a name="l00099"></a>00099         <span class="keywordflow">if</span> ($lname != <span class="stringliteral">&#39;&#39;</span>) {
<a name="l00100"></a>00100             $success *= mysql_query(<span class="stringliteral">&quot;UPDATE sysuser SET lname=&#39;$lname&#39; WHERE</span>
<a name="l00101"></a>00101 <span class="stringliteral">                    userID=$userID&quot;</span>);
<a name="l00102"></a>00102         }
<a name="l00103"></a>00103         <span class="keywordflow">if</span> ($permissionlevel != <span class="stringliteral">&#39;&#39;</span>) {
<a name="l00104"></a>00104             $success *= mysql_query(<span class="stringliteral">&quot;UPDATE sysuser SET</span>
<a name="l00105"></a>00105 <span class="stringliteral">                    permissionlevel=&#39;$permissionlevel&#39; WHERE userID=$userID&quot;</span>);
<a name="l00106"></a>00106         }
<a name="l00107"></a>00107         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00108"></a>00108     }
<a name="l00109"></a>00109 
<a name="l00115"></a><a class="code" href="classdb_user.html#a96e74a2261c118f3fe27bb38c91a41c8">00115</a>     <span class="keyword">static</span> <span class="keyword">function</span> <a class="code" href="classdb_user.html#a96e74a2261c118f3fe27bb38c91a41c8">addUser</a>($u, &amp;$id) {
<a name="l00116"></a>00116         <span class="keywordflow">if</span> (!$u instanceof <a class="code" href="class_user.html">User</a>) {
<a name="l00117"></a>00117             echo (<span class="stringliteral">&quot;Invalid argument addUser() function&lt;br /&gt;&quot;</span>);
<a name="l00118"></a>00118             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00119"></a>00119         }
<a name="l00120"></a>00120 
<a name="l00121"></a>00121         <span class="comment">//Compose the ADD query string. Primary key value is missing.</span>
<a name="l00122"></a>00122         <span class="comment">//Database server automatically generates a unique ID for the primary</span>
<a name="l00123"></a>00123         <span class="comment">//key.</span>
<a name="l00124"></a>00124         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = sprintf(<span class="stringliteral">&quot;INSERT INTO sysuser VALUES (null,&#39;%s&#39;, &#39;%s&#39;, &#39;%s&#39;, </span>
<a name="l00125"></a>00125 <span class="stringliteral">            &#39;%s&#39;, &#39;%s&#39;)&quot;</span>,
<a name="l00126"></a>00126                         $u-&gt;getUsername(),
<a name="l00127"></a>00127                         $u-&gt;getPassword(),
<a name="l00128"></a>00128                         $u-&gt;getFname(),
<a name="l00129"></a>00129                         $u-&gt;getLname(),
<a name="l00130"></a>00130                         $u-&gt;getPermissionLevel()
<a name="l00131"></a>00131         );
<a name="l00132"></a>00132         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00133"></a>00133         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00134"></a>00134         $id = mysql_insert_id();
<a name="l00135"></a>00135         mysql_close();
<a name="l00136"></a>00136         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00137"></a>00137             echo mysql_error();
<a name="l00138"></a>00138             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00139"></a>00139         }
<a name="l00140"></a>00140 
<a name="l00141"></a>00141         <span class="comment">//Query was successful.</span>
<a name="l00142"></a>00142         printf(<span class="stringliteral">&quot;User added has id %d\n&lt;br /&gt;&quot;</span>, mysql_insert_id());
<a name="l00143"></a>00143         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00144"></a>00144     }
<a name="l00145"></a>00145         
<a name="l00150"></a><a class="code" href="classdb_user.html#ab1daa973e2fd9382e927abfed005ceec">00150</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#ab1daa973e2fd9382e927abfed005ceec">getUserID</a>($u) {
<a name="l00151"></a>00151         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<span class="stringliteral">&quot;SELECT userID FROM sysuser WHERE</span>
<a name="l00152"></a>00152 <span class="stringliteral">            userID=&#39;$u&#39;&quot;</span>);
<a name="l00153"></a>00153         $row = mysql_fetch_row(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>);
<a name="l00154"></a>00154         <span class="keywordflow">return</span> $row[<span class="charliteral">&#39;0&#39;</span>];
<a name="l00155"></a>00155     }
<a name="l00156"></a>00156 
<a name="l00162"></a><a class="code" href="classdb_user.html#a8159dc3f41ea0543fe92a59134a6252e">00162</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#a8159dc3f41ea0543fe92a59134a6252e">getUsername</a>($u) {
<a name="l00163"></a>00163         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;SELECT username FROM sysuser</span>
<a name="l00164"></a>00164 <span class="stringliteral">        WHERE userID=&#39;$u&#39;&quot;</span>;
<a name="l00165"></a>00165         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00166"></a>00166         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00167"></a>00167         mysql_close();
<a name="l00168"></a>00168         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00169"></a>00169             echo mysql_error();
<a name="l00170"></a>00170             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00171"></a>00171         }
<a name="l00172"></a>00172         <span class="comment">//Query was successful.</span>
<a name="l00173"></a>00173         <span class="keywordflow">return</span> <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>;
<a name="l00174"></a>00174     }
<a name="l00175"></a>00175 
<a name="l00181"></a><a class="code" href="classdb_user.html#a904f14645853e94e078f5f9652bbd5a4">00181</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#a904f14645853e94e078f5f9652bbd5a4">getPassword</a>($u) {
<a name="l00182"></a>00182         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;SELECT password FROM sysuser</span>
<a name="l00183"></a>00183 <span class="stringliteral">        WHERE userID=&#39;$u&#39;&quot;</span>;
<a name="l00184"></a>00184         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00185"></a>00185         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00186"></a>00186         mysql_close();
<a name="l00187"></a>00187         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00188"></a>00188             echo mysql_error();
<a name="l00189"></a>00189             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00190"></a>00190         }
<a name="l00191"></a>00191         <span class="comment">//Query was successful.</span>
<a name="l00192"></a>00192         <span class="keywordflow">return</span> <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>;
<a name="l00193"></a>00193     }
<a name="l00194"></a>00194 
<a name="l00200"></a><a class="code" href="classdb_user.html#adc85ca8db9aaf9580462cb6bd4a4839a">00200</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#adc85ca8db9aaf9580462cb6bd4a4839a">getFname</a>($u) {
<a name="l00201"></a>00201         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;SELECT username FROM sysuser</span>
<a name="l00202"></a>00202 <span class="stringliteral">        WHERE userID=&#39;$u&#39;&quot;</span>;
<a name="l00203"></a>00203         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00204"></a>00204         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00205"></a>00205         mysql_close();
<a name="l00206"></a>00206         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00207"></a>00207             echo mysql_error();
<a name="l00208"></a>00208             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00209"></a>00209         }
<a name="l00210"></a>00210         <span class="comment">//Query was successful.</span>
<a name="l00211"></a>00211         <span class="keywordflow">return</span> <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>;
<a name="l00212"></a>00212     }
<a name="l00213"></a>00213 
<a name="l00219"></a><a class="code" href="classdb_user.html#aacfaf78bd00f5a75c0b1ed4e1ed60729">00219</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#aacfaf78bd00f5a75c0b1ed4e1ed60729">getLname</a>($u) {
<a name="l00220"></a>00220         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;SELECT lname FROM sysuser</span>
<a name="l00221"></a>00221 <span class="stringliteral">        WHERE userID=&#39;$u&#39;&quot;</span>;
<a name="l00222"></a>00222         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00223"></a>00223         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00224"></a>00224         mysql_close();
<a name="l00225"></a>00225         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00226"></a>00226             echo mysql_error();
<a name="l00227"></a>00227             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00228"></a>00228         }
<a name="l00229"></a>00229         <span class="comment">//Query was successful.</span>
<a name="l00230"></a>00230         <span class="keywordflow">return</span> <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>;
<a name="l00231"></a>00231     }
<a name="l00232"></a>00232 
<a name="l00238"></a><a class="code" href="classdb_user.html#adbfa127af600bc91ed5310fb3b321ea2">00238</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#adbfa127af600bc91ed5310fb3b321ea2">getPermissionLevel</a>($u) {
<a name="l00239"></a>00239         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;SELECT permissionLevel FROM sysuser</span>
<a name="l00240"></a>00240 <span class="stringliteral">        WHERE userID=&#39;$u&#39;&quot;</span>;
<a name="l00241"></a>00241         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00242"></a>00242         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00243"></a>00243         mysql_close();
<a name="l00244"></a>00244         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00245"></a>00245             echo mysql_error();
<a name="l00246"></a>00246             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00247"></a>00247         }
<a name="l00248"></a>00248         <span class="comment">//Query was successful.</span>
<a name="l00249"></a>00249         <span class="keywordflow">return</span> <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>;
<a name="l00250"></a>00250     }
<a name="l00251"></a>00251 
<a name="l00258"></a><a class="code" href="classdb_user.html#a1be72f507abfce98d3901d97d36985f5">00258</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#a1be72f507abfce98d3901d97d36985f5">checkID</a>($u) {
<a name="l00259"></a>00259         <span class="keywordflow">if</span> (!($u instanceof <a class="code" href="class_user.html">User</a>)) {
<a name="l00260"></a>00260             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00261"></a>00261         }
<a name="l00262"></a>00262         $userID = $u-&gt;getUserID();
<a name="l00263"></a>00263         <span class="keywordflow">if</span> (mysql_num_rows(mysql_query(<span class="stringliteral">&quot;SELECT * FROM sysuser WHERE</span>
<a name="l00264"></a>00264 <span class="stringliteral">                userID=$userID&quot;</span>)) == 0) {
<a name="l00265"></a>00265             <span class="comment">//nothing exists mysql_num_rows</span>
<a name="l00266"></a>00266             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00267"></a>00267         } <span class="keywordflow">else</span> {
<a name="l00268"></a>00268             <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00269"></a>00269         }
<a name="l00270"></a>00270     }
<a name="l00271"></a>00271 
<a name="l00278"></a><a class="code" href="classdb_user.html#aa6b5942ed208bcaaec016511cfc5fb1a">00278</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#aa6b5942ed208bcaaec016511cfc5fb1a">getUser</a>(<a class="code" href="db-control_2inc_2db_info_8php.html#a0eb82aa5f81cf845de4b36cd653c42cf">$username</a>) {
<a name="l00279"></a>00279         $user = <span class="keyword">new</span> <a class="code" href="class_user.html">User</a>();
<a name="l00280"></a>00280         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<span class="stringliteral">&quot;SELECT * FROM sysuser WHERE username=</span>
<a name="l00281"></a>00281 <span class="stringliteral">                &#39;$username&#39;&quot;</span>);
<a name="l00282"></a>00282         <span class="keywordflow">if</span> (!<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>) {
<a name="l00283"></a>00283             <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">//username does not exist</span>
<a name="l00284"></a>00284         } <span class="keywordflow">else</span> {
<a name="l00285"></a>00285             $row = mysql_fetch_assoc(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>);
<a name="l00286"></a>00286             $user-&gt;setUserName(<a class="code" href="db-control_2inc_2db_info_8php.html#a0eb82aa5f81cf845de4b36cd653c42cf">$username</a>);
<a name="l00287"></a>00287             $user-&gt;setPassword($row[<span class="stringliteral">&#39;password&#39;</span>]);
<a name="l00288"></a>00288             $user-&gt;setFName($row[<span class="stringliteral">&#39;fname&#39;</span>]);
<a name="l00289"></a>00289             $user-&gt;setLName($row[<span class="stringliteral">&#39;$lname&#39;</span>]);
<a name="l00290"></a>00290             $user-&gt;setPermissionLevel($row[<span class="stringliteral">&#39;permissionlevel&#39;</span>]);
<a name="l00291"></a>00291             <span class="keywordflow">return</span> $u;
<a name="l00292"></a>00292         }
<a name="l00293"></a>00293     }
<a name="l00294"></a>00294 
<a name="l00300"></a><a class="code" href="classdb_user.html#acc9588f8568c95f416325428bce85218">00300</a>     <span class="keyword">function</span> <a class="code" href="classdb_user.html#acc9588f8568c95f416325428bce85218">deleteUser</a>($u) {
<a name="l00301"></a>00301 
<a name="l00302"></a>00302         <span class="keywordflow">if</span> (!$u instanceof user) {
<a name="l00303"></a>00303             echo (<span class="stringliteral">&quot;Invalid argument deleteFrom() function&lt;br /&gt;&quot;</span>);
<a name="l00304"></a>00304             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00305"></a>00305         }
<a name="l00306"></a>00306 
<a name="l00307"></a>00307         <span class="comment">//Compose the DELETE FROM query string.</span>
<a name="l00308"></a>00308         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = sprintf(<span class="stringliteral">&quot;DELETE FROM sysuser WHERE username = &#39;%s&#39;&quot;</span>,
<a name="l00309"></a>00309                         $u-&gt;getUsername()
<a name="l00310"></a>00310         );
<a name="l00311"></a>00311         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>;
<a name="l00312"></a>00312         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00313"></a>00313         mysql_close();
<a name="l00314"></a>00314         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00315"></a>00315             echo mysql_error();
<a name="l00316"></a>00316             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00317"></a>00317         }
<a name="l00318"></a>00318 
<a name="l00319"></a>00319         <span class="comment">//Query was successful.</span>
<a name="l00320"></a>00320         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00321"></a>00321     }
<a name="l00322"></a><a class="code" href="classdb_user.html#aaaca33ac319178544c7cc9df0d9f1578">00322</a> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">function</span> <a class="code" href="classdb_user.html#aaaca33ac319178544c7cc9df0d9f1578">getAllByID</a>($id, &amp;$output) {
<a name="l00323"></a>00323         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = sprintf(<span class="stringliteral">&quot;SELECT username, password, fname,</span>
<a name="l00324"></a>00324 <span class="stringliteral">            lname, permissionlevel FROM sysuser WHERE</span>
<a name="l00325"></a>00325 <span class="stringliteral">            username=%d&quot;</span>, <a class="code" href="db-control_2inc_2db_info_8php.html#a0eb82aa5f81cf845de4b36cd653c42cf">$username</a>);
<a name="l00326"></a>00326         <span class="comment">//printf(&quot;-&gt;Query: %s&lt;br /&gt;&quot;, $query);</span>
<a name="l00327"></a>00327         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00328"></a>00328         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00329"></a>00329         mysql_close();
<a name="l00330"></a>00330 
<a name="l00331"></a>00331         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00332"></a>00332             $output = sprintf(<span class="stringliteral">&quot;%s&quot;</span>, mysql_error());
<a name="l00333"></a>00333             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00334"></a>00334         }
<a name="l00335"></a>00335         <span class="comment">//process result and print out warning or attribute values</span>
<a name="l00336"></a>00336         <span class="keywordflow">return</span> dbUser::checkForOneInstance(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>, $id, $output);
<a name="l00337"></a>00337     }
<a name="l00338"></a>00338 
<a name="l00339"></a>00339     <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">function</span> checkForOneInstance(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>, $id, &amp;$output) {
<a name="l00340"></a>00340         <span class="comment">//Local variables are initialized.</span>
<a name="l00341"></a>00341         $errorStatus = <span class="keyword">false</span>;
<a name="l00342"></a>00342 
<a name="l00343"></a>00343         $howMany = mysql_num_rows(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>);
<a name="l00344"></a>00344         printf(<span class="stringliteral">&quot;-&gt;Found %d instance(s) for userID=%d.&lt;br /&gt;&quot;</span>, $howMany, $id);
<a name="l00345"></a>00345         <span class="keywordflow">switch</span> ($howMany) {
<a name="l00346"></a>00346             <span class="keywordflow">case</span> 0:
<a name="l00347"></a>00347                 $output = sprintf(<span class="stringliteral">&quot;No User instance with ID=%d was found.&quot;</span>,
<a name="l00348"></a>00348                                 $id);
<a name="l00349"></a>00349                 $errorStatus = <span class="keyword">true</span>;
<a name="l00350"></a>00350                 <span class="keywordflow">break</span>;
<a name="l00351"></a>00351             <span class="keywordflow">case</span> 1:
<a name="l00352"></a>00352                 <span class="comment">//mysql_fetch() DOES NOT return primary key values</span>
<a name="l00353"></a>00353                 $output = mysql_fetch_assoc(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>);
<a name="l00354"></a>00354                 $errorStatus = <span class="keyword">false</span>;
<a name="l00355"></a>00355                 <span class="keywordflow">break</span>;
<a name="l00356"></a>00356             <span class="keywordflow">default</span>:
<a name="l00357"></a>00357                 $output = sprintf(<span class="stringliteral">&quot;There are multiple user instances with</span>
<a name="l00358"></a>00358 <span class="stringliteral">                                  ID=%d.&quot;</span>, $id);
<a name="l00359"></a>00359                 $errorStatus = <span class="keyword">true</span>;
<a name="l00360"></a>00360                 <span class="keywordflow">break</span>;
<a name="l00361"></a>00361         }
<a name="l00362"></a>00362         <span class="keywordflow">return</span> $errorStatus;
<a name="l00363"></a>00363     }
<a name="l00364"></a>00364 
<a name="l00365"></a>00365 }
<a name="l00366"></a>00366 
<a name="l00367"></a>00367 ?&gt;
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Tue Nov 29 2011 18:18:54 for i2c by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
